﻿// Test_RtspXPush.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <windows.h>
#include <stdint.h>
#include <list>
using namespace std;
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/XyRyNet_CommHdr.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/XyRyNet_ProtocolHdr.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/NetEngine_StreamMedia/StreamMedia_XStream/XStream_Define.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/NetEngine_StreamMedia/StreamMedia_XStream/XStream_Error.h"

#pragma comment(lib,"Ws2_32.lib")
#pragma comment(lib,"../../../../NetEngine_Windows/NetEngine_SourceCode/Debug/StreamMedia_XStream.lib")

int main()
{
	WSADATA st_WSAData;
	memset(&st_WSAData, '\0', sizeof(WSADATA));

	WSAStartup(MAKEWORD(2, 2), &st_WSAData);

	XNETHANDLE xhNet = 111;
	if (!XStream_ClientPush_Init(&xhNet, "127.0.0.1", 1931))
	{
		printf("XStream_ClientPush_Init %lX\n", XStream_GetLastError());
		return -1;
	}
	if (!XStream_ClientPush_PushHdr(xhNet))
	{
		printf("XStream_ClientPush_PushHdr %lX\n", XStream_GetLastError());
		return -1;
	}

	FILE* pSt_File = fopen("E:\\netengineapp\\NetEngine_WINApps\\Debug\\1080P.264", "rb");

	int i = 0;
	while (1)
	{
		TCHAR tszMsgBuffer[10240];
		memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
		int nRet = fread(tszMsgBuffer, 1, sizeof(tszMsgBuffer), pSt_File);
		if (nRet <= 0)
		{
			break;
		}
		if (XStream_ClientPush_PushPkg(xhNet, tszMsgBuffer, nRet))
		{
			printf("%d==%d\n", nRet, i++);
		}
		int nSleepTime = 0;
		XStream_ClientPush_GetSpeed(xhNet, &nSleepTime);
		Sleep(nSleepTime);
	}
	XStream_ClientPush_Close(xhNet);
	WSACleanup();
	return 0;
}